package com.nuc.zyt.day04.multiprocessing;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @ClassName Thread01
 * @Description TODO
 * @Author 耀酱
 * @Date 2023/5/29 18:48
 * @Version 1.0
 */

public class Thread01 extends Thread{
    @Override
    public void run() {
        // 执行线程
        System.out.println("继承Thread");
        int sum = 0;
        for (int i = 1; i <= 25; i++) {
            sum+=i;
            System.out.println(getName()+sum);
        }

    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 多线程三种实现
        // 1. 继承Thread
        Thread01 thread01 = new Thread01();
        Thread01 thread02 = new Thread01();
        thread01.setName("001线程");
        thread02.setName("002线程");

        thread01.start();
        thread02.start();

        // 2. 实现Runnable接口
        Thread1 thread1 = new Thread1();
        new Thread(thread1).start();
        new Thread(thread1).start();

        // 3. 实现Callable接口，Future接口
        Thread02 thread021 = new Thread02(); // 多线程要执行的任务

        FutureTask<Integer> integerFutureTask = new FutureTask<>(thread021); // 管理多线程运行的结果
        Thread thread = new Thread(integerFutureTask);
        thread.start();

        Integer integer = integerFutureTask.get();
        System.out.println(integer);


    }
}
